package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.miaodong.entity.AgentUserCollection;
import com.vf.admin.miaodong.entity.AppUserCollection;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class AgentUserCollectionDao extends BaseDao<AgentUserCollection> {
    /**
     * 保存或者更新
     */
    public void saveOrUpdate(AgentUserCollection baoMing) {
        if (baoMing!=null && baoMing.getId() != null && baoMing.getId()>0) {
            this.update(baoMing);
        } else {
            baoMing.setId(this.add(baoMing));
        }
    }

    //详情
    public AppUserCollection get(Integer id) {
        if(id==null || id<=0){
            return null;
        }
        return this.get(id, AppUserCollection.class);
    }

    //列表查询
    public List<AppUserCollection> findList(Map<String, Object> paraMap) {
        List<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append("select * from agent_user_collection ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppUserCollection.class);
    }

    //无参的列表查询
    public List<AppUserCollection> findList() {
        List<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append("select * from agent_user_collection");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppUserCollection.class);
    }

    /**
     * 删除
     */
    public void del(int id) {
        if (id <= 0) {
            return;
        }
        String sql = "delete  from agent_user_collection  where id = ?";
        ArrayList<Object> paramList = new ArrayList<>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    public AgentUserCollection findByUserId(Integer userId) {
        List<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append("select * from agent_user_collection where agentUserId = ?");
        paramList.add(userId);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AgentUserCollection.class);
    }

}
